package com.example.weatherforecast.data.city.persistence.repository

import android.content.Context
import com.example.weatherforecast.data.city.persistence.dao.CityInfoDao
import com.example.weatherforecast.data.city.persistence.database.CityInfoDatabase
import com.example.weatherforecast.data.city.persistence.entity.CityInfo
import com.example.weatherforecast.data.city.persistence.factory.CityInfoDatabaseFactory
import kotlinx.coroutines.newSingleThreadContext

class CityInfoRepository(val context: Context) {

    private val dbName = "weather-test"
    private var cityInfoDao: CityInfoDao ?= null

    init {
        cityInfoDao = CityInfoDatabaseFactory(context, dbName).getCityInfoDatabase().getCityInfoDao()
    }

    fun insertCityInfo(cityInfoList: List<CityInfo>) {
        cityInfoDao?.insert(cityInfoList)
    }

    fun queryByCityName(cityName: String): CityInfo? {
        return cityInfoDao?.queryByCityName(cityName)
    }

    fun queryAllCity(): List<CityInfo> {
        return cityInfoDao?.queryAll()!!
    }

    fun queryAllBlur(nameStr: String): List<CityInfo> {
        return cityInfoDao?.queryAllBlur(nameStr)!!
    }

    fun clearCityTableData(){
        cityInfoDao?.clearTableData()
    }

}